<?php
class MessageBaseControl extends Control
{
    public $content;
    public $status;
    public $childs = array();
    public $header;

    public function MessageBaseControl($content = null, $header = null)
    {
        if (is_array($content)) $content = Set::Enclose('<li>', $content, '</li>');
        $this->content = $content;
        $this->header = $header;
    }

    public function Render()
    {
        $flash['msg'] = $this->content.$this->RenderChilds();
        $flash['status'] = $this->status;
        $flash['display'] = $this->content ? 'display:static' : 'display:none';
        $flash['header'] = $this->header;
        return $flash;
    }

    public function AddChild($child)
    {
        $this->childs[] = $child;
    }

    public function RenderChilds()
    {
        $out = null;
        foreach ($this->childs as $child)
        {
            $flash = $child->Render();
            if (isset($_GET['expand']))
            {
                $toggle = null;
                $display = null;
            }
            else
            {
                $toggle = $flash['msg'] ? "<span class=\"msg_toggle\">[+]</span>" : null;
                $display = 'style="display:none"';
            }
            $out .=
                "<div class=\"messagebox {$flash['status']}\">
                    <div class=\"msg_header\">$toggle {$flash['header']}</div>
                    <div $display class=\"msg_content\">{$flash['msg']}</div>
                </div>";
        }
        return $out;
    }

}
?>
